<?php
/**
 * Created by PhpStorm.
 * User: xuke
 * Date: 16/6/12
 * Time: 下午2:50
 */

namespace App\Services;


class ApiResult
{
    private $_status = 0;
    private $_msg = "";
    private $_data = [];


    /**设置接口返回状态
     *
     * @param $status int
     * @return $this
     */
    public function setStatus($status)
    {
        $this->_status = $status;

        return $this;
    }

    public function getStatus()
    {
        return $this->_status;
    }

    /**设置接口返回错误信息
     *
     * @param $msg
     */
    public function setMsg($msg)
    {
        $this->_msg = $msg;

        return $this;
    }

    public function getMsg()
    {
        return $this->_msg;
    }

    public function setData($data)
    {
        $this->_data = $data;

        return $this;
    }

    public function getData()
    {
        return $this->_data;
    }

    public function ApiResult($status = 200)
    {
        $apiResult = [
            'status' => $this->getStatus(),
            'msg'    => $this->getMsg(),
            'data'   => $this->getData(),
        ];

        return response()->json($apiResult, $status);
    }

    public static function unLogin()
    {
        $apiResult = [
            'status' => -1,
            'msg'    => '该用户未登录',
            'data'   => [],
        ];
        return  response()->json($apiResult, 200);
    }
}